package dk.itu.mmad.travelapp3;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Checkout extends Fragment { 
	static String checkOut;
	static String checkIn;
	String tag = "CheckOut";
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.i(tag, "Died here?");
		final LinearLayout mll2 = (LinearLayout) inflater.inflate(R.layout.activity_checkout, container, false);
//		Button button  = (Button) mll2.findViewById(R.id.checkoutbutton);
//		button.setOnClickListener(new View.OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				EditText ed = (EditText) mll2.findViewById(R.id.checkoutstation);
//				checkOut = ed.getText().toString();
////				Intent intent= new Intent(getActivity());
////				intent.putExtra("ci", checkIn);
////				intent.putExtra("co", checkOut);
//				Log.i(tag, checkOut + " = check out"); 
//				Toast.makeText(getActivity(), checkOut, Toast.LENGTH_SHORT).show();
////				startActivity(intent);
//			}
//		});
		return mll2;
	}
	@Override
	public void onStart(){
		super.onStart();
		Button button2  = (Button) getActivity().findViewById(R.id.checkoutbutton);
		button2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				EditText ed = (EditText) getActivity().findViewById(R.id.checkinstation);
				checkIn = ed.getText().toString();
				EditText ed2 = (EditText) getActivity().findViewById(R.id.checkoutstation);
				checkOut = ed2.getText().toString();
				Toast.makeText(getActivity(), "findig a travel from: " + checkIn + " to: " + checkOut, Toast.LENGTH_LONG).show();
				Intent intent= new Intent(getActivity().getBaseContext(), Receipt.class);
				intent.putExtra("ci", checkIn);
				intent.putExtra("co", checkOut);
				Log.i(tag, checkOut + " = check out"); 
				startActivity(intent);
			}
		});
		
		
	}
}
